
package servlet.registration;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet(name = "addtoqualificationbean", urlPatterns = {"/addtoqualificationbean"})
public class addtoqualificationbean extends HttpServlet {

    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        //PrintWriter out = response.getWriter();
        AO.Seeker s=(AO.Seeker)request.getSession().getAttribute("seekerdata");
        AO.Login l=(AO.Login)request.getSession().getAttribute("logindata");
        String username=s.getUsername();
        AO.Qualification q=new AO.Qualification();
        int i=1;
        if(!request.getParameter("coursename1").equals(""))
        {
          try{DAO.LoginDAO.save(l); DAO.SeekerDAO.save(s);}catch(Exception sde){}
          while(!request.getParameter("coursename"+i).equals(""))
          {
            q.setUsername(username);
            q.setCoursename(request.getParameter("coursename"+i));
            q.setYop(request.getParameter("yop"+i));
            q.setBoard(request.getParameter("board"+i));
            q.setPercentage(Float.parseFloat(request.getParameter("percentage"+i)));
            q.setOptionals(request.getParameter("optionals"+i));
            DAO.QualificationDAO.save(q);
            i++;
          }
        
        if(s.getStatus().equals("fresher"))
        response.sendRedirect("seeker/");
        else if(s.getStatus().equals("experienced"))
        response.sendRedirect("experienceform.jsp");
        }
        else{response.sendRedirect("");}
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
